home *** CD-ROM | disk | FTP | other *** search
- package test.textui;
-
- import java.util.Enumeration;
- import test.framework.Test;
- import test.framework.TestFailure;
- import test.framework.TestResult;
-
- class TextTestResult extends TestResult {
- public synchronized void addError(Test test, Throwable t) {
- super.addError(test, t);
- System.out.println("E");
- }
-
- public synchronized void addFailure(Test test, Throwable t) {
- super.addFailure(test, t);
- System.out.print("F");
- }
-
- public synchronized void startTest(Test test) {
- super.startTest(test);
- System.out.print(".");
- }
-
- public void printErrors() {
- if (((TestResult)this).testErrors() != 0) {
- if (((TestResult)this).testErrors() == 1) {
- System.out.println("There was " + ((TestResult)this).testErrors() + " error:");
- } else {
- System.out.println("There were " + ((TestResult)this).testErrors() + " errors:");
- }
-
- int i = 1;
-
- for(Enumeration e = ((TestResult)this).errors(); e.hasMoreElements(); ++i) {
- TestFailure failure = (TestFailure)e.nextElement();
- System.out.println(i + ") " + failure.failedTest());
- failure.thrownException().printStackTrace();
- }
- }
-
- }
-
- public void printFailures() {
- if (((TestResult)this).testFailures() != 0) {
- if (((TestResult)this).testFailures() == 1) {
- System.out.println("There was " + ((TestResult)this).testFailures() + " failure:");
- } else {
- System.out.println("There were " + ((TestResult)this).testFailures() + " failures:");
- }
-
- int i = 1;
-
- for(Enumeration e = ((TestResult)this).failures(); e.hasMoreElements(); ++i) {
- TestFailure failure = (TestFailure)e.nextElement();
- System.out.print(i + ") " + failure.failedTest());
- Throwable t = failure.thrownException();
- if (t.getMessage() != null) {
- System.out.println(" \"" + t.getMessage() + "\"");
- } else {
- System.out.println();
- failure.thrownException().printStackTrace();
- }
- }
- }
-
- }
-
- public synchronized void print() {
- this.printHeader();
- this.printErrors();
- this.printFailures();
- }
-
- public void printHeader() {
- if (((TestResult)this).wasSuccessful()) {
- System.out.println();
- System.out.print("OK");
- System.out.println(" (" + ((TestResult)this).runTests() + " tests)");
- } else {
- System.out.println();
- System.out.println("!!!FAILURES!!!");
- System.out.println("Test Results:");
- System.out.println("Run: " + ((TestResult)this).runTests() + " Failures: " + ((TestResult)this).testFailures() + " Errors: " + ((TestResult)this).testErrors());
- }
-
- }
- }
-